﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IEx.Common
{
    public class DataFeedConfiguration : ConfigurationSection
    {
        public static DataFeedConfiguration GetConfig()
        {
            return ConfigurationManager.GetSection("IEx") as DataFeedConfiguration;
        }

        [ConfigurationProperty("email", IsRequired = true)]
        public EmailElement EmailSetting
        {
            get
            {
                return this["email"] as EmailElement;
            }
        }

        [ConfigurationProperty("downloadFolder", IsRequired = true)]
        public DownloadFolderElement DownloadedFolder
        {
            get
            {
                return this["downloadFolder"] as DownloadFolderElement;
            }
        }
    }

    public class DownloadFolderElement : ConfigurationElement
    {
        [ConfigurationProperty("path")]
        public string Path
        {
            get { return (string)this["path"]; }
        }
    }

    public class EmailElement : ConfigurationElement
    {
        [ConfigurationProperty("allowed", DefaultValue = "True")]
        private string _Allowed
        {
            get
            {
                return (string)this["allowed"];
            }
        }

        public bool Allowed
        {
            get
            {
                bool allowed = true;
                bool.TryParse(this._Allowed, out allowed);
                return allowed;
            }
        }

        [ConfigurationProperty("smtpHost", IsRequired = true)]
        public string SmtpHost
        {
            get
            {
                return (string)this["smtpHost"];
            }
        }

        [ConfigurationProperty("smtpPort", IsRequired = true)]
        public string SmtpPort
        {
            get
            {
                return (string)this["smtpPort"];
            }
        }

        [ConfigurationProperty("senderEmailAddress", IsRequired = true)]
        public string SenderEmailAddress
        {
            get
            {
                return (string)this["senderEmailAddress"];
            }
        }

        [ConfigurationProperty("senderEmailPassword", IsRequired = true)]
        public string SenderEmailPassword
        {
            get
            {
                return (string)this["senderEmailPassword"];
            }
        }

        [ConfigurationProperty("senderAlias", IsRequired = true)]
        public string SenderAlias
        {
            get
            {
                return (string)this["senderAlias"];
            }
        }

        [ConfigurationProperty("subject", IsRequired = true)]
        public string Subject
        {
            get
            {
                return (string)this["subject"];
            }
        }

        [ConfigurationProperty("toEmailAddress", IsRequired = true)]
        public string ToEmailAddress
        {
            get
            {
                return (string)this["toEmailAddress"];
            }
        }

        [ConfigurationProperty("alertEmail")]
        public string AlertEmail
        {
            get
            {
                return (string)this["alertEmail"];
            }
        }
    }
}
